package com.yunti.springboot.controller;



import com.yunti.springboot.annotation.IgnoreLog;
import com.yunti.springboot.annotation.Log;
import com.yunti.springboot.annotation.Permission;
import com.yunti.springboot.service.impl.ApiLogServiceImpl;
import com.yunti.springboot.vo.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * <p>
 * api请求记录表 前端控制器
 * </p>
 *
 * @author ytt
 * @since 2022-03-27
 */
@RestController
@RequestMapping("/apiLog")
public class ApiLogController {

    @Resource
    ApiLogServiceImpl service;
    @IgnoreLog
    @ResponseBody
    @RequestMapping(value = "/getApiLogs", method = RequestMethod.GET)
    //通过页面大小、条数开始和结束时间对日志记录筛选
    public Result getApiLogs(@RequestParam(value = "pageNum", required = false) Integer pageNum, @RequestParam(value = "pageSize", required = false) Integer pageSize, String userName, String state, String startTime, String endTime ) {
        return service.getApiLogs(pageNum, pageSize,userName, state, startTime, endTime );
    }

    @Permission({"superAdmin"})
    @ResponseBody
    @RequestMapping(value = "/deleteById", method = RequestMethod.POST)
    //通过id对日志记录删除
    public Result deleteById(@RequestParam(value = "id", required = false) Integer id){
        return service.deleteById(id);
    }

    @Permission({"superAdmin"})
    @ResponseBody
    @RequestMapping(value = "/delBatchById", method = RequestMethod.POST)
    //通过id数组对日志记录批量删除
    public Result deleteListById(@RequestParam(value = "ids",required = false)Integer ids[]){
        return service.delBatchById(ids);
    }
}
